#include <iostream>
#include <cmath>
/*辗转相除法*/
int gcd(int x, int y)
{
    /*max=18,min=12*/
    int max = std::max(x, y);
    int min = std::min(x, y);
    int r = max % min;
    while (r != 0)
    {
        max = min;
        min = r;
        r = max % min;
    }
    return min;
}
class Point
{
    friend double Distance(const Point &p1, const Point &p2);
    friend class Line;

public:
    Point(int x, int y)
    {
        this->x = x;
        this->y = y;
    }
    void show()
    {
        std::cout << "(" << x << "," << y << ")" << std::endl;
    }

private:
    int x;
    int y;
};
class Line
{
private:
    double A;
    double B;
    double C;

public:
    Line(double A, double B, double C) : A(A), B(B), C(C) {}
    Line(const Point &p1, const Point &p2)
    {
        A = p2.y - p1.y;
        B = p1.x - p2.x;
        C = p1.x * p2.y - p2.x * p1.y;
        int r = gcd(gcd(A, B), C);
        A /= r;
        B /= r;
        C /= r;
    }
    void show()
    {
        std::cout << A << "x+" << B << "y+" << C << "=0" << std::endl;
    }
    double Distance(const Point &p)
    {
        double distance = 1.0 * abs(A * p.x + B * p.y + C) / sqrt(A * A + B * B);
        return distance;
    }
};
double Distance(const Point &p1, const Point &p2)
{
    return sqrt(pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2));
}
int main()
{
    Point p(1, 2);
    Point p1(2, 3);
    Line L(p, p1);
    std::cout << Distance(p, p1) << std::endl;
    std::cout << L.Distance(p) << std::endl;
    p.show();
    L.show();
}